<template>
	<view>
		<button @click="get">发送get请求</button>
		<button @click="setStorage">存储数据</button>
		<button @click="getStorage">获取数据</button>
		<view>这是列表页</view>
		<view class="box-item" v-for="item in list">
			{{item}}
		</view>
		<button @click="pullDown">下拉刷新</button>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				list: ['前端', 'Java', '前端', 'Java', 'UI', '测试', '大数据','UI', '测试', '大数据','前端', 'Java', 'UI', '测试', '大数据']
			}
		},
		onPullDownRefresh() {
			console.log('出发下拉刷新了')
			setTimeout(()=>{
				this.list=['前端1', 'Java1', 'UI1', '测试1', '大数据1']
				uni.stopPullDownRefresh()
			},2000)
		},
		onReachBottom() {
			console.log('页面触底了')
			//在原有数据的基础上再加5条新数据
			this.list=[...this.list,...['前端2', 'Java3', 'UI3', '测试3', '大数据3']]
		},
		methods:{
			pullDown(){
				uni.startPullDownRefresh()
			},
			get(){
				uni.request({
					url:'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
					success: (res) => {
						console.log(res)
					}	
				})
			},
			setStorage(){
				uni.setStorage({
					key:'id',
					data:80,
					success() {
						console.log('存储成功')
					}
				})
			}
		}
	}
</script>

<style>
	.box-item{
		height: 100rpx;
		line-height: 100rpx;
	}
</style>
